<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/global.css" media="all">
    <script type="text/javascript" src="/plugins/layui/layui.js"></script>
    <title>交易对新增</title>
    <style type="text/css">
        .searcheBottom{margin-bottom: 10px;}
    </style>
</head>
<body>
<div class="admin-main">
<blockquote class="layui-elem-quote">
    <div class="demoTable">
        <div class="layui-inline searcheBottom">
            <div class="layui-inline" style="margin-right: 30px;">
                <h3><b>当前交易所：${exchangeName!}</b></h3>
                <input id="exchangeId" name="exchangeId" class="layui-input" style="display: none" value="${id!}"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            币种名称：
            <div class="layui-inline">
                <input id="transactionName" class="layui-input" name="transactionName" autocomplete="off" placeholder="币种名称"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            法币名称：
            <div class="layui-inline">
                <input id="enName" class="layui-input" name="enName" autocomplete="off" placeholder="法币名称"/>
            </div>
        </div>
        <div class="layui-inline searcheBottom">
            <a class="layui-btn" data-type="reload" id="search">搜索</a>
            <a class="layui-btn layui-btn-primary" id="reset">重置</a>
            <button id="traadd" class="layui-btn">添加</button>
            <a href="/manage/extrading/ecList?id=${id!}&exchangeName=${exchangeName!}" class="layui-btn" style="float: right;">返回</a>
        </div>
    </div>
</blockquote>
<span style="font-size: 16px;"><b>交易对列表</b></span>
<table class="layui-hide" id="traTable" lay-filter="tableFilter"></table>
</div>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.use(['jquery','table','laydate','layer','form','util'],function(){
        var $=layui.jquery,table=layui.table,laydate = layui.laydate,
            layer = layui.layer,form = layui.form,util=layui.util;
        var exchangeId =parseInt("${id!}");//获取交易所id
        //表格渲染
        pageInit();
        function pageInit() {
            table.render({
                elem:"#traTable",
                url:"/manage/extrading/ntralist",
                where:{exchangeId:exchangeId},
                method:"post",
                cols:[[
                    {type:'checkbox'},
                    {field:'id', title: 'ID', sort: true,align:'center'},
                    {field:'', title: '交易对',align:'center',templet:function (d) {
                        return d.transactionName + "/" +d.enName;
                    }},
//                    {field:'enName', title: '法币名称',align:'center'},
                    {field:'updateTime', title: '修改时间',sort: true,align:'center',
                        templet: function(d){
                            if(d.updateTime !=null){
                                return util.toDateString(d.updateTime, 'yyyy-MM-dd HH:mm:ss');
                            }else {
                                return '';
                            }
                        }
                    },
                ]],
                limits:[10,15,20,25,30],
                limit:10,
                page:true
            });
        }

        //表格重载
        var active = {
            reload: function () {
                var transactionName = $('#transactionName');
                var enName = $('#enName');
                var exchangeId = $('#exchangeId');
                table.reload('traTable', {
                    where: {
                        transactionName: transactionName.val(),
                        enName:enName.val(),
                        exchangeId:exchangeId.val()
                    }
                });
            }
        };

        //将搜索框的值随请求传到后台
        $('.demoTable #search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $(".layui-input").keydown(function (e) {
            if(e.keyCode == 13){
                $('#search').click();
            }
        });

        //重置
        $("#reset").on("click",function(){
            transactionName.value = '';
            enName.value = '';
        });

        $('#traadd').on('click', function(){
            var checkStatus = table.checkStatus('traTable')
                ,data = checkStatus.data;
            var checkList = JSON.stringify(data);
            if(data.length < 1){
                layer.msg('请选择数据', { icon: 7, shift: 6 });
            }else {
                $.ajax({
                    url:"/manage/extrading/addtransaction",
                    type:"post",
                    data:{"checkList":checkList,"exchangeId":$('#exchangeId').val()},
                    dataType:"json",
                    success:function (res) {
                        if(res.code ==0){
                            layer.msg(res.msg, { icon: 6, shift: 6 });
                            pageInit();
                        }
                    }
                })

            }
        });
    });

</script>
</body>
</html>